package io.github.jianjianghui.groot.demo;

import io.github.jianjianghui.groot.core.GrootException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="https://www.github.com/jianjianghui">Jianghui Jian<a/>
 * @date 2021/9/6 - 11:39
 */
@RestControllerAdvice
public class WebExceptionHandler {

    @ExceptionHandler(GrootException.class)
    public Map<Object, Object> webExceptionHandler(GrootException grootException) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("code", grootException.getCode());
        hashMap.put("message", grootException.message());
        return hashMap;
    }

}
